﻿namespace AlgorithmInterview.Chapter01._01;

/// <summary>
/// 方法三：插入法
/// </summary>
public class Test03
{
    public static void Reverse(LNode head)
    {
        // 判断链表是否为空
        if (head == null || head.next == null)
            return;

        LNode cur = null; // 当前结点 
        LNode next = null; // 后继结点
        cur = head.next.next;
        // 设置链表第一个结点为尾结点
        head.next.next = null;
        // 把遍历到结点插入到头结点的后面
        while (cur != null)
        {
            next = cur.next;
            cur.next = head.next;
            head.next = cur;
            cur = next;
        }
    }
}